﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SelectedJsonValues.ascx.cs"
    Inherits="DMS.Web.Common.Controls.SelectedJsonValues" %>
<div id="dvHolder" runat="server">
    <table cellpadding="0" cellspacing="0" border="0" width="100%">
        <tr>
            <td>已选择项：（注：双击删除选择项）</td>
            <td style="width:70px; text-align:right;"><span onclick="javascript:Clear();" style="cursor:pointer;">全部清空</span></td>
        </tr>
    </table>
    <asp:ListBox ID="lbSelectedItems" runat="server" Width="100%" Rows="10" SelectionMode="Multiple">
    </asp:ListBox>
</div>
<asp:HiddenField ID="hidRootTitle" runat="server" Value="Items" />
<asp:HiddenField ID="hidItemTitle" runat="server" Value="Item" />
<script language="javascript" type="text/jscript">
<!--
    var mode = '<%=Request.QueryString["Mode"] %>' == '' ? 'Multiple' : '<%=Request.QueryString["Mode"] %>'; //Multiple or Single
    function GetSelectedItems() {
        var selector = document.getElementById("<%=lbSelectedItems.ClientID %>");
        var str = "";

        for (var index = 0; index < selector.options.length; index++) {
            var val = selector.options[index].value;
            if ("<%=ItemTitle %>" == "") {
                str += (val + "<%=ItemSeparator %>");
            }
            else {
                str += val;
            }
        }

        if (str == "") {
            return "";
        }

        if ("<%=RootTitle %>" != "") {
            //str = "<%=RootTitleBegin %>" + str + "<%=RootTitleEnd %>";
        }
        else if (str.lastIndexOf("<%=ItemSeparator %>") == str.length - 1) {
            str = str.substring(0, str.length - 1);
        }
        //alert(str);
        return str;
    }

    function AddItem(textStr, valueStr) {

        var selector = document.getElementById("<%=lbSelectedItems.ClientID %>");
        if (mode == 'Single') {
            for (var index = 0; index < selector.options.length; index++) {
                selector.remove(index);
            }
        } else {
            for (var index = 0; index < selector.options.length; index++) {
                if (selector.options[index].value == valueStr) {
                    return;
                }
            }
        }

        var item = document.createElement("OPTION");
        item.text = textStr;
        item.value = valueStr;

        selector.add(item, 0);
    }

    function RemoveItem(selector) {
        if (selector == null || selector.selectedIndex == -1) {
            return;
        }

        selector.remove(selector.selectedIndex);
    }

    function Clear() {
        var selector = document.getElementById("<%=lbSelectedItems.ClientID %>");
        while (selector.options.length > 0) {
            selector.remove(0);
        }
    }
//-->
</script>
